package com.briup.jz.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.briup.jz.bean.CertificationApply;
import com.briup.jz.bean.CertificationApplyExample;
import com.briup.jz.bean.extend.CertificationApplyExtend;
import com.briup.jz.dao.CertificationApplyMapper;
import com.briup.jz.dao.extend.CertificationApplyExtendMapper;
import com.briup.jz.service.ICertificationService;
import com.briup.jz.utils.CustomerException;
@Service
public class CertificationServiceImpl implements ICertificationService{
	
	 	@Resource
	    private CertificationApplyMapper certificationMapper;
	 	@Autowired
		private CertificationApplyExtendMapper certificationApplyExtendMapper;

	    @Override
	    public List<CertificationApply> findAll() {
	        return certificationMapper.selectByExample(new CertificationApplyExample());
	    }

	    @Override
	    public CertificationApply findById(long id) {
	        return certificationMapper.selectByPrimaryKey(id);
	    }

	    @Override
	    public void saveOrEdit(CertificationApply certification) throws CustomerException {
	        if(certification.getId()==null){
	        	certificationMapper.insert(certification);
	        }else{
	            if(certificationMapper.selectByPrimaryKey(certification.getId())==null){
	                throw new CustomerException("修改失败，数据不存在");
	            }
	            certificationMapper.updateByPrimaryKey(certification);
	        }
	    }

	    @Override
	    public void delById(long id){
	        if(certificationMapper.selectByPrimaryKey(id)==null){
	            System.out.println("shuju"+certificationMapper.selectByPrimaryKey(id));
	            throw new CustomerException("删除失败，数据不存在");
	        }
	        certificationMapper.deleteByPrimaryKey(id);
	    }
	    
		@Override
		public List<CertificationApplyExtend> queryCascade(String realName, String status, Long userId) {
			// TODO Auto-generated method stub
			return certificationApplyExtendMapper.select(realName, status, userId);
		}
}
